[Savestates] Fix world resourcepacks not correctly applying after savestate #255
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It's always fascinating on how much you learn when trying to fix issues like this...
If start a world and it has a "resources.zip" in the world folder, it is widely known that Minecraft will attempt to load this resourcepack. Map makers have been using this feature for a while now...
What I didn't know is that it actually sets up that rp to be a "server resourcepack", so that people joining via LAN also have the same RP.
While the host of the LAN server is accessing this RP directly, the client is only downloading it once to their system and then load it.
So the problem in this case is the host, as loadstates will try to delete the current world and the host, still having access to the RP, will fail to delete it.
So the solution is to:
Unloading the host RP turned out a bit complicated, as unloading a RP schedules multiple actions on a different thread, meaning a future had to be used to make the server wait until the client-host has cleared it's RP.
And that also needed a countdown latch, to make the client wait, as that happens on yet another thread...
Finally a good portion of my time went into figuring out, that a association with a file has to be cleared by running the garbage collector, otherwise savestates would still fail even though the RP was visibly unloaded.
And for good measure, I added a simple warning to the loadstating process if a resources.zip is present, in case anyone is wondering why savestating takes 5 times longer than usual.
The end result is that you can easily load different RPs with savestates, so you can make some creative stuff with different RPs for different sections of something...
Fixes #204